package com.digitalchina.lxnsy.activity.old;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.bigkoo.pickerview.OptionsPickerView;
import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.base.BaseActivity;
import com.digitalchina.lxnsy.entity.URLVO;
import com.digitalchina.lxnsy.toolkit.GotoUtil;
import com.digitalchina.lxnsy.xml.UserDefinedServerXML;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.activity
 * 创建人：郑皓
 * 创建时间：2017/3/27 15:25
 * 修改备注：
 * ================================================
 */
public class SetAppURLActivity extends BaseActivity {

    @Bind(R.id.set_app_tv_url)
    TextView setAppTvUrl;
//    @Bind(R.id.set_app_btn_come)
//    Button setAppBtnCome;

    private OptionsPickerView option;
    private List<URLVO> urlvoList = new ArrayList<>();
    private boolean isCome = false;

    @Override
    public void setLayout() {
        setContentLayout(R.layout.activity_set_app_url);
    }

    @Override
    public void initMember() {
        setTitle("设置连接");
        initData();
    }

    private void initData() {

        urlvoList.add(new URLVO("9099演示环境", "http://61.150.65.204:9099/"));
        urlvoList.add(new URLVO("8090开发环境", "http://61.150.65.204:8090/"));
        urlvoList.add(new URLVO("8888外网测试环境", "http://61.150.65.224:8888/"));
        urlvoList.add(new URLVO("生产开发环境<慎用>", "http://www.yladc.com/"));

        option = new OptionsPickerView.Builder(SetAppURLActivity.this, new OptionsPickerView.OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int option2, int options3, View v) {
                setAppTvUrl.setText(urlvoList.get(options1).getUrlName());
                UserDefinedServerXML.setURL(SetAppURLActivity.this, urlvoList.get(options1).getUrladdress());
                isCome = true;
            }
        })
                .setSubCalSize(16)//确定取消按钮大小
                .setLineSpacingMultiplier(1.5f) //设置两横线之间的间隔倍数（范围：1.2 - 2.0倍 文字高度）
                .setDividerColor(getResources().getColor(R.color.colorFontLightGrayB))//设置分割线的颜色
                .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
                .setContentTextSize(18)//设置滚轮文字大小
                .setSelectOptions(0)  //设置默认选中项
                .build();

        option.setPicker(urlvoList);
    }

    @Override
    public void addListener() {

    }

    @Override
    public void setHandler() {

    }

    @Override
    public void callBack(Object object) {

    }

    @Override
    public void rightOnClick() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.set_app_tv_url, R.id.set_app_btn_come})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.set_app_tv_url:
                if (option != null)
                    option.show();
                break;
            case R.id.set_app_btn_come:
                if (isCome) {
//                    URL.SERVER = UserDefinedServerXML.getURL(SetAppURLActivity.this);
                    GotoUtil.gotoActivity(SetAppURLActivity.this, MainActivity.class);
                }
                else
                    showToast("请选择服务器地址啊!");
                break;
        }
    }
}
